<template>
    <div>
        <el-dialog
            title="教师管理"
            :visible.sync="dialogVisible"
            @closed="close"
            :close-on-click-modal="false"
            @open="open"
            width="700px">
            <el-table
                    ref="table"
                    :data="tableData"
                    size="small"
                    stripe
                    border
                    style="width: 100%">
                    <el-table-column
                    label="头像"
                    prop="T_Photo"
                    width="120">
                        <template slot-scope="scope">
                            <img :src="scope.row.T_Photo" alt="用户头像" class="user-img">
                        </template>
                    </el-table-column>
                    <el-table-column
                    prop="T_Name"
                    label="姓名"
                    min-width="120">
                    </el-table-column>
                    <el-table-column
                    prop="T_Mobile"
                    label=" 手机号"
                    min-width="120">
                    </el-table-column>
                    <el-table-column
                    label="操作"
                    width="130">
                        <template slot-scope="scope">
                            <el-button  @click="handleClickedit(scope.row)" type="text" size="small"><i class="el-icon-edit"></i>编辑</el-button>
                            <el-button  @click="handleClickdelete(scope.row)" type="text" size="small"><i class="el-icon-delete"></i>删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="bottom-pages clearfix">
                    <el-button class="fl" @click="handleClickAdd" type="primary" size="small">新增</el-button>
                    <div class="fr">
                        <el-pagination
                        background
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-size="10"
                        :pager-count="5"
                        layout="total, prev, pager, next"
                        :total="count">
                        </el-pagination>
                    </div>
                </div>
        </el-dialog>
        <ele-add-teacher ref="addteacher" :title="addTitle" :eidtinfo="eidtinfo" @addsuccess="getteacherInfoInit"></ele-add-teacher>
    </div>
</template>
<script>
// 添加康复记录
const img = require('./../../assets/u466.png');
import {getteacher,deletteacher} from '@/api/index.js'
import eleAddTeacher from './add-teacher.vue'
export default {
    components:{
        eleAddTeacher
    },
    data() {
        return {
            dialogVisible:false,
            tableData:[],
            count:0,
            currentPage:1,
            addTitle:'新增教师',
            eidtinfo:''
        }
    },
    methods:{
       open(){
            this.getteacherInfoInit()
        },
        getteacherInfoInit() {
            this.currentPage = 1;
            this.getteacherInfo()
        },
        getteacherInfo() {
            let params = {
                bT_Name:'',
                bPage:(this.currentPage - 1) * 10 + 1,
                bPage1:this.currentPage * 10,
                bSort:'',
                bSx:''
            };
            getteacher(params).then((res) => {
                console.log(res)
                if(res) 
                {
                    this.tableData = res.tableData;
                    this.count = res.total_rows;
                }
            })
        },
        handleSizeChange(){

        },
        handleCurrentChange(val){
            this.currentPage = val;
            this.getteacherInfo()
        },
        handleClickedit(row){
            this.addTitle = '编辑教师';
            this.eidtinfo = row;
            this.$refs.addteacher.dialogVisible = true;
            
        },
        handleClickAdd(){
            this.addTitle = '新增教师';
            this.eidtinfo = "";
            this.$refs.addteacher.dialogVisible = true;
        },
        // 删除
        handleClickdelete(row){
            this.$util.openTips.call(this,'是否确定删除？')
            .then((res) => {
                deletteacher({bTID:row.TID}).then((res) => {
                    if(res) {
                        this.$util.tipsMsg('success','删除成功！');
                        this.getteacherInfo();
                    }
                }).catch((err) => {
                    console.log(err)
                })
            }).catch((err) => {
                console.log(err)
            })
        },
        handleClickLook(row){
            this.$refs.lookinfo.dialogVisible = true;
            this.romeinfo = row.CR_QD;
        },
        close(){

        }
    }
}
</script>
<style lang="less" scoped>
.user-img{
    width: 30px;
    height: 30px;
    border-radius: 50%;
}
</style>
